/**
 * 
 */
package cn.edu.scau.cmi.chenzehan.client;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.edu.scau.cmi.chenzehan.springFrame.bean.Student;
import cn.edu.scau.cmi.chenzehan.springFrame.bean.Teacher;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;

public class UiSpringFrame extends Application{

	private Parent root;
	private Button button1;
	private Button button2;
	private TextArea ta;
	
	@Override
	public void start(Stage primaryStage) throws Exception {
		
		root = FXMLLoader.load(getClass().getResource("spring.fxml"));
		
		button1 = (Button)root.lookup("#button1");
		button2 = (Button)root.lookup("#button2");
		ta= (TextArea) root.lookup("#ta");
		
		button1.setOnAction(e->{
			ta.appendText("教师信息如下"+"\n");
			ApplicationContext ctx = new ClassPathXmlApplicationContext("cn/edu/scau/cmi/chenzehan/springFrame/applicationContext.xml");
		    Teacher teacher = (Teacher) ctx.getBean("liangzaoqing");
		    ta.appendText("教师姓名：" + teacher.getName()+"\n");
		    ta.appendText("教师性别：" + teacher.getGender()+"\n");
		    ta.appendText("教师工号：" + teacher.getId()+"\n");
		});
		
		button2.setOnAction(e->{
			ta.appendText("学生信息如下"+"\n");
			ApplicationContext ctx = new ClassPathXmlApplicationContext("cn/edu/scau/cmi/chenzehan/springFrame/applicationContext.xml");
		    Student student = (Student) ctx.getBean("chenzehan");
		    ta.appendText("学生姓名：" + student.getName()+"\n");
		    ta.appendText("学生性别：" + student.getGender()+"\n");
		    ta.appendText("学生学号：" + student.getId()+"\n");
		    ta.appendText("学生指导老师姓名：" + student.getTeacher().getName()+"\n");
		});
		
		Scene scene = new Scene(root);
		primaryStage.setTitle("Spring框架");
		primaryStage.setScene(scene);
		primaryStage.show();
	}
	public static void main(String[] args) {
		launch(args);
	}

}
